from AlgCollection import AlgColletion
from dirManager import dirManager
from resources import resources
from Experiment import Experiment
from tools import *
import os

print "##########" + 'WORKING IN malibu-GLUE' + "##########"
#setup work location
d = dirManager("/projects/membraneTargeting")
print "#WORKING IN DIRECTORY: " + d.dirs['main']

#load algorithms
coll = AlgColletion(['c45boost','adtree'])

#coll = AlgColletion(['adtree'])
coll.setup()
print "#AVAILABLE ALGORITHMS: " + str(coll.coll.keys())

#load training sets 
trainFiles = d.getDatasetList()
print "#TRAINING SETS: "
print str([os.path.basename(p) for p in trainFiles])
#do normalization
#for t in trainFiles:
    #mmNorm(t)

#load machine resources set parameter to 1 to load remote machines
res = resources(0)
print "#AVAILABLE MACHINES: "
print [m.name for m in res.rlist]
print "##########################################"

#parameters

canonical = [['bagend:','5'],['label:','1']]

specific = {} #algorith specific pars


itePars = [[['nfold:','5']],[['nfold:','4']]]

iteraSpecific = {} #parameters to iterate over for a specific algorithm 
specific['adtree'] = [['iterations:', '10-100+2']]
specific['libsvm'] = [['pwgt_gaus:','0-2+0.1'],['nwgt_gaus:','0-2+0.1'],['cost_gaus:' '1-128*2']]
specific['c45boost'] = [['boost_metric:','F-score'],['cf:','0.15-0.85+0.03']]
tsSpecific = {}
#tsSpecific['SmallMichi_Test.dataset'] = [['label:','1']]


#create runs to feed to experiment
runs = []
for alg in coll.coll.items():
    for s in trainFiles:
        for p in itePars:
            r = alg[1].getRun()
            r.setValue([['trainfile:',s]])
            r.setValue(canonical)
            r.setValue(p)
            if(specific.has_key(alg[1].name)):
                r.setValue(specific[alg[1].name])
            if(tsSpecific.has_key(os.path.basename(s))):
                r.setValue(tsSpecific[os.path.basename(s)])
            runs.append(r)
            
#create experiment
desc = 'attempt to make into MIL problem'
exp = Experiment("Mulyipletest", desc, runs, d.dirs['exp'], res)

exp.letsGo()



